package com.woniu.tms.attendance.service.impl;

import com.woniu.tms.entity.Sickform;
import com.woniu.tms.entity.SickformExample;
import com.woniu.tms.entity.User;
import com.woniu.tms.attendance.service.SickFormService;
import com.woniu.tms.mapper.SickformMapper;
import com.woniu.tms.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @Author: peng
 */
@Service
@Transactional
public class SickFormServiceImpl implements SickFormService {
    @Autowired
    UserMapper userMapper;
    @Autowired
    SickformMapper sickformMapper;

    @Override
    public List<User> listTmBySid(Integer uid) {

        return userMapper.listTmBySid(uid);
    }

    @Override
    public User selectByUid(Integer uid) {
        return userMapper.selectByPrimaryKey(uid);
    }

    @Override
    public void add(Sickform sickform) {
        sickformMapper.insertSelective(sickform);
    }



    @Override
    public void update(Sickform sickform) {
        sickformMapper.updateByPrimaryKeySelective(sickform);
    }

    @Override
    public Sickform selectOne(Integer sid) {
        return sickformMapper.selectByPrimaryKey(sid);
    }

    /**
     * 根据学生id查询其历史请假信息，并按照sid进行排序
     * @param studentid
     * @return
     */
    @Override
    public List<Sickform> listSickInfoByStudentid(Integer studentid) {
        SickformExample example = new SickformExample();
        SickformExample.Criteria criteria = example.createCriteria();
        criteria.andStudentidEqualTo(studentid);
        example.setOrderByClause("sid desc");
        return sickformMapper.selectByExample(example);
    }

    /**
     * 根据sid
     * @param sid
     */
    @Override
    public void delete(Integer sid) {
        sickformMapper.deleteByPrimaryKey(sid);
    }


    /**
     * 根据讲师id或班主任id查询状态为待审批需要其审批的请假信息
     *
     * @param confirmid
     * @return
     */
    @Override
    public List<Sickform> listSickInfo(Integer confirmid) {
        SickformExample example = new SickformExample();
        SickformExample.Criteria criteria = example.createCriteria();
        criteria.andConfirmidEqualTo(confirmid);
        criteria.andStatusEqualTo("待审批");
        return sickformMapper.selectByExample(example);
    }
}
